#!/bin/bash
#
#               Status Bar under Terminal
#   
#                       antzcn@gmail.com

# colors to use
  BLACK="[30m"
    RED="[31m"
  GREEN="[32m"
 YELLOW="[33m"
   BLUE="[34m"
MAGENTA="[35m"
   CYAN="[36m"
  WHITE="[37m"

# seperator between items
SEPTOR=$BLACK"|"$BLUE

# start of string 
STRS=
# end of string
STRE=
# the string of functions
RESULT=

# show current time
TIME()
{
    RESULT+=`date +%H:%M:%S`
}

# show current tty name
TTY()
{
    ttyname=`tty|awk -F/ '{print $3}'`
    if [ "$ttyname" == pts ]; then ttyname=pts/`tty|awk -F/ '{print $4}'`;fi;
    RESULT+=$ttyname
}

# check eth0
ETH0()
{
    ifconfig eth0 | grep RUNNING > /dev/null
    if [ $? != 0 ]; then RESULT+=$RED; fi;
    RESULT+=eth0;
}

# update the status bar
Update()
{
    RESULT=
    RESULT+=$BLUE
    TTY
    RESULT+=$SEPTOR
    ETH0
    RESULT+=$SEPTOR
    TIME
}

Update
# colums of console
COL=`stty size|awk '{print $2}'`
# length of status bar
LEN=`echo -n $RESULT|wc -c`
# Location (X, Y) of status bar start
X=$(($COL - $LEN + 24))
Y=1

# save cursor position
STRS+="[s"
# set cursor position
STRS+="[$Y;$X""H"
# set graphics mode
STRS+="[47m"
# restore cursor position
STRE+="[u"

while [ 1 ]
    do
    Update
    echo -ne $STRS $RESULT $STRE
    usleep 500
done
